package com.talent.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.talent.common.PageConstants;
import com.talent.dao.CourseMapper;
import com.talent.page.Page;
import com.talent.pojo.Course;
import com.talent.service.CourseService;
@Service
public class CourseServiceImpl implements CourseService{
	@Autowired
	CourseMapper courseMapper;
	
	@Override
	public Page<Course> selectCoursePage(Course course, int currentPage) {
		Page<Course> page = new Page<>(currentPage, PageConstants.PAGESIZE);
        List<Course> courseList = courseMapper.selectCoursePage(course, page);
        page.setResultList(courseList);
        return page;
	}

	@Override
	public Course selectById(Integer id) {
		return courseMapper.selectByPrimaryKey(id);
	}

	@Override
	public void editCourse(Course course) {
		Course c = courseMapper.selectByPrimaryKey(course.getId());
		c.setCode(course.getCode());
		c.setName(course.getName());
		c.setIntroduction(course.getIntroduction());
		courseMapper.updateByPrimaryKeySelective(c);
	}

	@Override
	public int addCourse(Course course) {
		return courseMapper.insert(course);
	}

	@Override
	public void deleteById(Integer id) {
		courseMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void deleteAll(String[] ids) {
		courseMapper.deleteAll(ids);
		
	}

	@Override
	public int selectCount(String code) {
		return courseMapper.selectCount(code);
	}

}
